add<{extend name="public/base"}>
<{block name="foot_source"}>
<script type="text/javascript" src="/static/webuploader/webuploader.js"></script>
<link rel="stylesheet" type="text/css" href="/static/webuploader/webuploader.css">
<{/block}>
<{block name="content"}>
<!-- left column -->
<div class="col-md-12">
    <!-- general form elements -->
    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title"><{$title}></h3>
        </div>
        <!-- /.box-header -->
        <!-- form start -->
        <form role="form" action="<{:url('admin/style/handle')}>" method="post" id="form">
            <div class="box-body">
                <div class="form-group">
                    <label for="title">风格名称</label>
                    <input type="text" class="form-control" id="title" name="title" value="<{$model.title}>" placeholder="请输入风格名称">
                </div>
                <div class="form-group">
                    <label for="desc">风格说明</label>
                    <input type="text" class="form-control" id="desc" name="desc" value="<{$model.desc}>" placeholder="请输入风格说明">
                </div>

                <div>
                    <label>缩略图</label>
                    <div id="cover-container"></div>
                </div>
                <div id="uploader" class="wu-example">
                    <!--用来存放文件信息-->
                    <div id="thelist" class="uploader-list"></div>
                    <div class="btns">
                        <input type="hidden" class="form-control" value="<{$model.cover}>" id="cover" name="cover" />
                        <img src="<{$model.cover}>" id="cover_show" />
                        <div id="picker">选择文件</div>
                    </div>
                </div>


                <div>
                    <label>风格详情图列表</label>
                    <div id="image-list-container">
                        <?php if(!empty($model->image_list)) {?>

                        <?php foreach($model->image_list as $key => $src ) {?>
                        <div style="width:100px;float:left;text-align:center;margin:10px;">
                            <img src="<{$src}>"  style="width:100px;height:100px;margin-bottom:5px;" data-src="<{$src}>"/>
                            <div>
                                <span class="btn btn-warning btn-sm del">删除</span>
                                <span class="btn btn-success btn-sm move-to-right">-></span>
                            </div>
                        </div>
                        <?php } ?>
                        <?php }?>
                    </div><!---详情列表--->
                    <div class="clearfix"></div>
                    <div id="image_list">
                        <?php if(!empty($model->image_list)) { ?>
                        <?php foreach($model->image_list as $key => $src ) {?>
                        <input type='hidden' value='<{$src}>' name='image_list[]' />
                        <?php } ?>
                        <?php } ?>
                    </div>
                </div>
                <div id="uploader2" class="wu-example">
                    <!--用来存放文件信息-->
                    <div id="thelist2" class="uploader-list"></div>
                    <div class="btns">
                        <div id="picker2">选择文件</div>
                    </div>
                </div>


            </div>
            <!-- /.box-body -->
            <input type="hidden"  value="<{$model->id}>" name="id" />
            <div class="box-footer">
                <a href="javascript:;" type="submit" class="btn btn-primary" id="submit">提交</a>
            </div>
        </form>
    </div>
    <!-- /.box -->
</div>


<{/block}>
<{block name="foot_script"}>
<script type="text/javascript">
    var BASE_URL = '/static/webuploader';
    var uploader = WebUploader.create({
        // swf文件路径
        swf: BASE_URL + '/js/Uploader.swf',
        // 文件接收服务端。
        server: '/admin/api/upload',
        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: '#picker',
        // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
        resize: false,
        duplicate: true
    });

    // 当有文件被添加进队列的时候
    uploader.on( 'fileQueued', function( file ) {
        uploader.upload();
    });

    // 文件上传成功，给item添加成功class, 用样式标记上传成功。
    uploader.on( 'uploadSuccess', function( file,data ) {
        $("#cover").val(data.url);
        $("#cover_show").attr('src',data.url);
    });

    var uploader2 = WebUploader.create({
        swf: BASE_URL + '/js/Uploader.swf',
        server: '/admin/api/upload',
        pick: '#picker2',
        resize: false,
        duplicate: true //实现重复上传
    });

    uploader2.on('fileQueued',function(file){
        uploader2.upload();
    });

    uploader2.on('uploadSuccess',function(file,data){
        var image = '<div style="width:100px;float:left;text-align:center;margin:10px;">' +
            '<img src="'+data.url+'"  style="width:100px;height:100px;margin-bottom:5px;" data-src="'+data.url+'"/>' +
            '<div><span class="btn btn-warning btn-sm del">删除</span> <span class="btn btn-success btn-sm move-to-right">-></span></div>' +
            '</div>';
        $("#image-list-container").append(image);

    });

    var imageShow = document.createElement('img');
    imageShow.style.display = 'none';
    document.body.appendChild(imageShow);
    $("#image-list-container").delegate('img','mouseover',function(){
        imageShow.src = $(this).attr('src');
        imageShow.style.cssText = "width:"+imageShow.width+"px;height:"+imageShow.height+"px;display:block;position:fixed;left:50%;top:50%;margin-left:-"+(imageShow.width)/2 + "px;margin-top:-"+(imageShow.height)/2+"px;";
    });
    $("#image-list-container").delegate('img','mouseleave',function(){
        imageShow.style.display = 'none';
    });
    $("#image-list-container").delegate('.del','click',function(){
        $(this).parent().parent().remove();
    });
    $("#image-list-container").delegate('.move-to-right','click',function(){
        var $dom = $(this).parent().parent();
        var $next = $dom.next();
        $next.after($dom);
    });

    $("#submit").click(function(){
        $("#image_list").html("");
        $("#image-list-container img").each(function(index,item){
            $("#image_list").append("<input type='hidden' value='"+$(item).data('src')+"' name='image_list[]' />");
        });
        $("#form").submit();
    });
</script>
<{/block}>


